package com.palnar.ilecker.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.ksoap2.serialization.SoapObject;

import com.palnar.ilecker.utils.XmlDocumentUtility;

public class ServiceEndPoint<T> extends ItemBase implements Serializable  {

	private Integer sepClientId;
	private Integer sepServerId;
	private Integer hotelId;
	//private String name;
	List<ServiceStation> serviceStations;
	
	public ServiceEndPoint() 
	{
		this.serviceStations = new ArrayList<ServiceStation>();
	}

	public Integer getSEPClientId() 
	{
		return this.sepClientId;
	}
	
	public Integer getSEPServerId() 
	{
		return this.sepServerId;
	}

//	 public String getSEPName() 
//	 {
//		 return this.name;
//	 }
	 public Integer getHotelId()
	 {
		 return this.hotelId;
	 }

	public List<ServiceStation> GetServiceStations()
	{
		return serviceStations;
	}

	public void setSEPClientId(Integer serviceEndPointId) 
	{
		this.sepClientId = serviceEndPointId;
	}

	public void setSEPServerId(Integer serviceEndPointId) 
	{
		this.sepServerId = serviceEndPointId;
	}
	
//	public void setSEPName(String serviceEndPointName) 
//	{
//		this.name = serviceEndPointName;
//	}
	
	 public void setHotelId(Integer hotelId)
	 {
		 this.hotelId = hotelId;
	 }	

	 public void setServiceStations(List<ServiceStation> serviceStations) 
	 {
	   this.serviceStations = serviceStations;
	 }
	
	public void AddServiceStation(ServiceStation serviceStation)
	{
		this.serviceStations.add(serviceStation);
	}
	
	public ServiceStation TryGetServiceStation(Integer serviceStationId)
	{	
		if(!this.serviceStations.isEmpty())
		{
			for (ServiceStation serviceStation : this.serviceStations) {
			if(serviceStation.getClientId() == serviceStationId)
			{
				return serviceStation;
			}
			}
		}
		return null;
	}
	
	
	public static ServiceEndPoint<ServiceStation> ServiceEndPointTypeBuilder(SoapObject object) {

		ServiceEndPoint<ServiceStation> serviceEndPoint = new ServiceEndPoint<ServiceStation>();

		Object OrderServiceEndPointIdObj = object
				.getProperty("OrderServiceEndPointId");

		if (!OrderServiceEndPointIdObj.toString().equals(
				XmlDocumentUtility.nullString)) {
			serviceEndPoint.setSEPServerId(Integer
					.parseInt(OrderServiceEndPointIdObj.toString()));
		}

		Object ServiceEndPointNameObj = object
				.getProperty("OrderServiceEndPointName");

		if (!ServiceEndPointNameObj.toString().equals(XmlDocumentUtility.nullString)) {
			serviceEndPoint.setName(Integer
					.parseInt(ServiceEndPointNameObj.toString()));
		}
		
	
		
		int serviceStationCount = ((SoapObject) object
				.getProperty("ServiceStations")).getPropertyCount();

		SoapObject serviceStationSoapObject = (SoapObject) object
				.getProperty("ServiceStations");
		for (int i = 0; i < serviceStationCount; i++) {
			serviceEndPoint.serviceStations.add(ServiceStation
					.ServiceStationTypeBuilder((SoapObject) serviceStationSoapObject
							.getProperty(i)));
		}
		
		return serviceEndPoint;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
